        package cn.code.admin.web;


import cn.code.admin.model.AuthReRolePower;
import cn.code.admin.dao.AuthReRolePowerMapper;
import cn.code.admin.constant.constant;
import cn.code.admin.dto.ExceptionMessage;
import cn.code.admin.dto.Message;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;

/**
 * Created by wangYuDong on 2017/5/10.
 */
@Controller
@RequestMapping("/authReRolePower")
public class AuthReRolePowerController {
    @Resource
    private AuthReRolePowerMapper authReRolePowerMapper;

    @ResponseBody
    @RequestMapping(value="/get",method = RequestMethod.GET)
    public Page<AuthReRolePower> getUserList(Page<AuthReRolePower> page){
        page.setRecords( authReRolePowerMapper.selectPage(page,new EntityWrapper<AuthReRolePower>()));
        return page;
    }

    @ResponseBody
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Message authReRolePowerAdd(AuthReRolePower authReRolePower){
        Integer i=authReRolePowerMapper.insert(authReRolePower);
        if(i>0){
            return new Message("添加成功");
        }else{
            return new ExceptionMessage("添加失败",constant.ERROR_USER+constant.ERROR_CREATE);
        }
    }

    @ResponseBody
    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public Message authReRolePowerDelete(@PathVariable  Integer id){
        Integer i=authReRolePowerMapper.deleteById(id);
        if(i>0){
            return new Message("删除成功");
        }else{
            return new ExceptionMessage("删除失败",constant.ERROR_USER+constant.ERROR_DELETE);
        }
    }

    @ResponseBody
    @RequestMapping(value = "/{id}",method =RequestMethod.PATCH)
    @ApiOperation(value="修改",httpMethod = "PATCH")
    public Message  authReRolePowerUpdate(@PathVariable Integer id,AuthReRolePower authReRolePower){
        authReRolePower.setId(id);
        Integer i=authReRolePowerMapper.updateById(authReRolePower);
        if(i>0){
            return new Message("更新成功");
        }else{
            return new ExceptionMessage("更新失败",constant.ERROR_USER+constant.ERROR_UPDATE);
        }
    }
}
